package com.toe.forum.webapi.controller;


import com.toe.common.restful.JsonPage;
import com.toe.common.restful.JsonResult;
import com.toe.forum.service.ForumAlbumService;
import com.toe.pojo.dto.forum.AlbumAddDTO;
import com.toe.pojo.dto.forum.AlbumUpdateDTO;
import com.toe.pojo.vo.forum.AlbumVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 相册 前端控制器
 * </p>
 *
 * @author 陶涛
 * @since 2022-07-19
 */
@RestController
@RequestMapping("/forum-album")
@Api(tags = "相册模块")
public class ForumAlbumController {

    @Autowired
    private ForumAlbumService forumAlbumService;

    @ApiOperation("添加图片到相册")
    @PostMapping("/insert")
    public JsonResult<Void> insert(@RequestBody AlbumAddDTO albumAddDTO){
        forumAlbumService.insert(albumAddDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除对应id的图片")
    @PostMapping("/delete/{id}")
    public JsonResult<Void> deleteById(@PathVariable long id){
        forumAlbumService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改对应id的图片")
    @PostMapping("/update")
    public JsonResult<Void> updateAlbum(@RequestBody AlbumUpdateDTO albumUpdateDTO){
        forumAlbumService.updateAlbum(albumUpdateDTO);
        return JsonResult.ok();
    }

    @ApiOperation("查询相册中的全部图片")
    @GetMapping("/select/list")
    public JsonResult<List<AlbumVO>> selectAllAlbum(){
        List<AlbumVO> albumVOS = forumAlbumService.selectAllAlbum();
        return JsonResult.ok(albumVOS);
    }

    @ApiOperation("分页查询相册中的全部图片")
    @GetMapping("/select/list/page")
    public JsonResult<JsonPage<AlbumVO>> selectAllAlbumPage(Integer pageNum,Integer pageSize){
        JsonPage<AlbumVO> albumVOJsonPage = forumAlbumService.selectAllAlbumPage(pageNum, pageSize);
        return JsonResult.ok(albumVOJsonPage);
    }

    @ApiOperation("根据文章id查询某个文章的全部图片")
    @GetMapping("/select/article/{articleId}")
    public JsonResult<List<AlbumVO>> selectAllAlbumByArticleId(@PathVariable long articleId){
        List<AlbumVO> albumVOS = forumAlbumService.selectAllAlbumByArticleId(articleId);
        return JsonResult.ok(albumVOS);
    }

    @ApiOperation("根据文章id分页查询某个文章的全部图片")
    @GetMapping("/select/article/{articleId}/page")
    public JsonResult<JsonPage<AlbumVO>> selectAllAlbumByArticleIdPage(@PathVariable long articleId,Integer pageNum,Integer pageSize){
        JsonPage<AlbumVO> albumVOJsonPage = forumAlbumService.selectAllAlbumByArticleIdPage(articleId, pageNum, pageSize);
        return JsonResult.ok(albumVOJsonPage);
    }

    @ApiOperation("查询某一张图片")
    @GetMapping("/select/{id}")
    public JsonResult<AlbumVO> selectAlbumById(@PathVariable long id){
        AlbumVO albumVO = forumAlbumService.selectAlbumById(id);
        return JsonResult.ok(albumVO);
    }

}

